#include "StdAfx.h"
#include "SubStructure.h"
#include "Mediator.h"
#include "Player.h"

void Player::Init()
{
}

void Player::Move(DWORD keystate)
{
}

void Player::SlowMove(DWORD keystate)
{
}

void Player::Shoot()
{
	if(nowState == SHOOTED)
	{
		return;
	}
	EventList tempE;
	if(!(shootcount % FastBullet1.DoTime))
	{
		Event_struct* temp = new Event_struct(FastBullet1);
		tempE.push_back(temp);
	}
	if(!(shootcount % FastBullet2.DoTime))
	{
		Event_struct* temp = new Event_struct(FastBullet2);
		tempE.push_back(temp);
	}
	mediator->GetEvent(tempE);
}

void Player::SlowShoot()
{
	if(nowState == SHOOTED)
	{
		return;
	}
	EventList tempE;
	if(!(shootcount % SlowBullet1.DoTime))
	{
		Event_struct* temp = new Event_struct(SlowBullet1);
		tempE.push_back(temp);
	}
	if(!(shootcount % SlowBullet2.DoTime))
	{
		Event_struct* temp = new Event_struct(SlowBullet2);
		tempE.push_back(temp);
	}
	mediator->GetEvent(tempE);
}

void Player::Draw()
{
}

void Player::SetAni(AniVec2 nAni)
{
	_Ani = nAni;
	_now_Ani = *_Ani[0][0];
	now_Ani_State1 = 0;
	now_Ani_State2 = 0;
	now_Ani_count = 0;
}

void Player::SetAniState(DWORD now)
{
	now_Ani_State1 = now;
	now_Ani_State2 = 0;
	_now_Ani = *_Ani[now_Ani_State1][now_Ani_State2];
	now_Ani_count = 0;
}

void Player::AniUpdate()
{
	shootcount++;
	now_Ani_count++;
	if(now_Ani_count >= _now_Ani.this_cut_count)
	{
		if(now_Ani_State2 >= (_Ani[now_Ani_State1].size() - 1))
		{
			SetNowState(_Ani[now_Ani_State1][now_Ani_State2]->next_ani);
		}
		else
		{
			++now_Ani_State2;
			_now_Ani = *_Ani[now_Ani_State1][now_Ani_State2];
		}
		now_Ani_count = 0;
	}

	if(nowState == SHOOTED)
	{
		stateTick--;
		if(stateTick == 0)
		{
			nowState = LIVE;
			SetNowState(INVINCIBLE);
		}
	}
}

void Player::Shooted()
{
	SetNowState(SHOOTED);
	now_Ani_State1 = SHOOTED;
	now_Ani_State2 = 0;
	_now_Ani = *_Ani[now_Ani_State1][now_Ani_State2];
	now_Ani_count = 0;
}

D3DXVECTOR2 Player::GetPos(){ return nowPos; }

void Player::SetPos(D3DXVECTOR2 nPos){ nowPos = nPos; }

void Player::SetBound(BoundBoxVec nbound){ boundBox = nbound; }

void Player::SetPowerCount(DWORD addCount){PowerCount = addCount;}

void Player::AddPowerCount(DWORD addCount){PowerCount = addCount;}

DWORD Player::GetPowerCount(){return PowerCount;}

BoundBoxVec Player::GetBound(){ return boundBox; }

void Player::SetNowState(DWORD nS)
{
	nowState = nS;
	SetAniState(nowState);
	if(nS == SHOOTED)
	{
		stateTick = 60;
	}
}

DWORD Player::GetNowState()
{
	return nowState;
}

Player::Player()
{
	_Ani.clear();
	mediator = Mediator::Instance();
	nowState = 0;
	stateTick = 0;
	shootcount = 0;
	PowerCount = 0;
	now_Ani_State1 = 0;
	now_Ani_State2 = 0;
	now_Ani_count = 0;
	soulAni_State1 = 0;
	soulAni_State2 = 0;
	soulAni_count = 0;
}

Player::~Player()
{
	int i, j;
	i = _Ani.size();
	int ii, jj;
	for(ii = 0; ii < i; ++ii)
	{
		j = _Ani[ii].size();
		for(jj = 0; jj < j; ++jj)
		{
			delete _Ani[ii][jj];
		}
	}

	i = _soulAni.size();
	for(ii = 0; ii < i; ++ii)
	{
		j = _soulAni[ii].size();
		for(jj = 0; jj < j; ++jj)
		{
			delete _Ani[ii][jj];
		}
	}

	i = boundBox.size();
	for(ii = 0; ii < i; ++ii)
	{
		delete boundBox[ii];
	}
}